<?php
/*
	我的购物车
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['lang']){
	$_SESSION['show_lang']=$_RQ['lang'];
}
$merchid=$this->checklogin();
$return['item']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
if(!$return['item'] && !$_RQ['isstore']){
	$_SESSION['uid']=0;
	//exi('找不到会员信息！请先登陆！','error','jy_weishop/account.login/');
}
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['params']=array();
	$up_hour=$this->setting['up_hour'];
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$lastdaytime=$daytime-24*3600;
	if($up_hour){
		$nowhour=date('H');
		if($up_hour>intval($nowhour)){
			$daytime=$lastdaytime+$up_hour*3600;
		}else{
			$daytime=$daytime+$up_hour*3600;
		}
	}
	$return['total']=0;
	$return['isselectall']=1;
	if(!$this->setting['print_pcd']){
		$return['log']= pdo_get('jy_supplier_log',array('merchid'=> $merchid, 'uniacid' => $_SESSION['uniacid'],'createtime >'=>$daytime));
		$return['list']=json_decode($return['log']['goods'],true);
		$return['list']=array_values($return['list']);
		foreach($return['list'] as &$gv){
			$gv['unit']=pdo_getcolumn('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),'unit');
			$gv['image']=pdo_getcolumn('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),'image');
			$gv['printnum']=$gv['num']-intval($gv['isprintnum']);
			$gv['lastprintnum']=$gv['printnum'];
			$gv['selected']=1;
			$return['total'] +=$gv['printnum'];
		}
	}else{
		$return['list']=array();
	}
	$return['print_pcd']=$this->setting['print_pcd'];
	$this->session('logid',$return['log']['id']);
	set_html('title','打印标签');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('merchid'=>$merchid,'uniacid'=>$_SESSION['uniacid'],'isprint'=>0,'orderid >'=>0);
	$orderby='id desc';
	if(!$_RQ['status']){
		$params['status']=0;
	}
	$credit_types=credit_types();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_supplier_log',$params,array($pindex,$psize),$total,'','',$orderby);
	$work_weekarray=array('日','一','二','三','四','五','六');
	if($list){
		foreach($list as &$item){
			$item['goods']=json_decode($item['goods'],true);
			foreach($item['goods'] as &$gv){
				$gv['unit']=pdo_getcolumn('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),'unit');
				$gv['image']=pdo_getcolumn('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),'image');
				$gv['printnum']=$gv['num']-intval($gv['isprintnum']);
				$gv['lastprintnum']=$gv['printnum'];
				$item['printnum'] +=$gv['printnum'];
			}
			$item['selected']=1;
			$item['is_addtitle']=$item['is_add']?'获得':'消费';
			$item['statustitle']=$this->log_status[$item['status']];
			$week = date('w', $item['createtime']);
			$item['week'] = '星期'.$work_weekarray[$week];
			$item['days']=date('Y-m-d', $item['createtime']);
			$item['depot']=pdo_get('jy_supplier_depot',array('id'=>$item['depot_id'],'uniacid'=>$_SESSION['uniacid']));
			$item['depot']['pcd']=json_decode($item['depot']['pcd'],true);
			$item['signurl']=custom_url('jy_supplier/signlog/up/id='.$item['id'],true);
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='print'){
	$goods=get_postdata();
	$print_pcd=$_RQ['print_pcd'];
	$logid=$this->session('logid');
	$this->model('pei')->upprint($logid,$goods,'',$print_pcd);
	exi('打印成功');
}
if($_RQ['op']=='goodsprint'){
	$logid=$_RQ['logid'];
	$goodskey=$_RQ['goodskey'];
	$item= pdo_get('jy_supplier_log',array('id'=> $logid,'uniacid' => $_SESSION['uniacid']));
	$item['goods']=json_decode($item['goods'],true);
	$onegoods=$item['goods'][$goodskey];
	$onegoods['printnum']=$onegoods['num'];
	$goods[]=$onegoods;
	$this->model('pei')->upprint($logid,$goods);
	exi('打印成功');
}
?>